<template>
  <div>
    <div class="banner">假装是广告</div>

    <div class="base">
      <div class="list-con">

        <div 
          v-for="item in goodsList"
          :key="item.id"
          class="item"
          @click="$router.push({name: 'productDetails', params:{id: item.id}})"
        >
          <div class="goods-img"><img :src="item.cover"/></div>
          <div class="goods-msg">
            <div class="goods-name">{{ item.name }}</div>
            <div class="goods-price">
              <div class="price">￥{{ item.price }}</div>
            </div>
          </div>
        </div>


      </div>
    </div>
  </div>

</template>

<script setup>
import request from '@/utils/request';
import { onMounted, ref } from 'vue';

const goodsList = ref([])

onMounted
(
  async () =>
  {
    const res = await request.post('/home.php')
    if (res.stat !== 1)
    {
      return
    }

    goodsList.value = res.data
  }
)
</script>

<style scoped>
.base {
  background: #f9f9f9
}

.list-con {
  width: 1200px;
  max-width: 1200px;
  margin: auto;
  padding-bottom: 40px;
  display: flex;
  flex-wrap: wrap;
}


.list-con .item {
  position: relative;
  width: 232px;
  height: 320px;
  background: #fff;
  margin-top: 20px;
  margin-right: 10px;
  cursor: pointer;
  -moz-transition: all .2s;
  -webkit-transition: all .2s;
  -o-transition: all .2s;
  transition: all .2s;
  box-sizing: border-box;
}

.list-con .item:hover {
  opacity: .8
}

.list-con .item:nth-child(4n) {
  margin-right: 10px
}

.list-con .item:nth-child(5n) {
  margin-right: 0
}

.list-con .item:nth-child(n+6) {
  margin-top: 10px
}


.list-con .item .goods-img {
  width: 170px;
  height: 170px;
  line-height: 170px;
  text-align: center;
  font-size: 0;
  margin: 30px auto
}

.list-con .item .goods-img img {
  max-width: 100%;
  max-height: 100%;
  vertical-align: middle
}

.list-con .item .goods-msg {
  text-align: center;
  padding: 15px 15px 0
}

.list-con .item .goods-msg .goods-name {
  width: 170px;
  margin: 0 auto;
  height: 17px;
  line-height: 14px;
  font-size: 14px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}


.list-con .item .goods-msg .goods-price {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  height: auto;
  line-height: 16px;
  font-weight: 700;
  color: #e1251b;
  margin-top: 10px;
  overflow: hidden
}

.list-con .item .goods-msg .goods-price .price {
  margin-right: 10px
}

.banner {
  width: 100%;
  height: 200px;
  font-size: 50px;
  font-weight: bold;
  text-align: center;
  background-color: darkred;
  color: white;
  padding: 100px;

}
</style>

